import { notReadGroupList } from '../../index/account';
import { SelfSuggestList, AdminSuggestList } from "../../index/suggest";
import { Http } from '../../model/base/http';

export class NotiStore extends Http {
    suggestList!: SelfSuggestList;
    adminSuggestList!: AdminSuggestList;
    groupList!: notReadGroupList;
    types: string[];
    constructor() {
        super()
        this.types = []
        if (!NotiStore.instance) {
            this.suggestList = new SelfSuggestList()
            this.adminSuggestList = new AdminSuggestList()
            this.groupList = new notReadGroupList()
            this.getTypeList().then(() => this.init())
            NotiStore.instance = this
        } else {
            return NotiStore.instance
        }
    }
    init() {
        this.getSuggest();
        this.getGroupList();
        if (this.types.includes("suggestList")) {
            this.getAdminSuggest();
        }
    }
    get total() {
        const { suggestList, groupList, adminSuggestList } = this
        return suggestList.total + groupList.total + adminSuggestList.total
    }
    async getTypeList() {
        this.types = await this.request('/v1/token/getMessageTypes')
    }
    getSuggest() {
        return this.suggestList.refresh(1)
    }
    getAdminSuggest() {
        return this.adminSuggestList.refresh(1)
    }
    getGroupList() {
        return this.groupList.refresh(1)
    }
    static instance: NotiStore
}